<?php
/**
 * Created by PhpStorm.
 * User: andy
 * Date: 16/4/9
 * Time: 12:22
 */
class Model_LotteryUsers extends PhalApi_Model_NotORM {

    function getbyopenid($openid) {
        return $this->getORM()
            ->where("openid",$openid)
            ->count("id");
    }

    function insertUser($user) {
        return $this->getORM()
            ->insert($user);

    }
    function updatebyopenid($openid,$info){
        return $this->getORM()
            ->where("openid",$openid)
            ->update($info);
    }


    function userInfoByOpenid($openid) {
        return $this->getORM()
            ->where("openid",$openid)
            ->fetch();
    }


    function gettotal() {
        return $this->getORM()
            ->count("id");
    }

    function gettotalByToday() {
        return $this->getORM()
            ->where("DATE(lotterytime)",DATE("Y-m-d"))
            ->count("id");
    }

    function gettotalUser($openid) {
        return $this->getORM()
            ->where("openid",$openid)
            ->count("id");
    }

    function gettotalUserByToday($openid) {
        return $this->getORM()
            ->where("openid",$openid)
//            ->where("DATE(lotterytime)",DATE("Y-m-d"))
//            ->where("DATE(lotterytime) = to_days(now())")
            ->count("id");
    }


    protected function getTableName($id) {
        return 'wxvk_Lottery_Users';
    }


}